package com.ik.hiddevice;

import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;

import com.ik.hiddevice.listener.OnBlueScanListener;
import com.ik.hiddevice.listener.OnBondStateChanedListener;
import com.ik.hiddevice.listener.OnSuccessListener;
import com.ik.hiddevice.utlis.LogUtil;

public class MyService extends Service implements OnBlueScanListener, OnBondStateChanedListener, OnSuccessListener {

    private static final String TAG = "MyService";
    @Override
    public void onCreate() {
        super.onCreate();
        LogUtil.showLogD(TAG,"onCreate->");
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if (mBluetoothAdapter == null){
            LogUtil.showLogE(TAG,"设备没有蓝牙模块！");
            Toast.makeText(this,"设备没有蓝牙模块！",Toast.LENGTH_SHORT).show();
            stopSelf();
            return;
        }
        blueToothHelper1 = new BlueToothHelper1(this,mBluetoothAdapter);
    }

    private BluetoothAdapter mBluetoothAdapter;
    private BlueToothHelper1 blueToothHelper1;
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        blueToothHelper1.start(this,mBluetoothAdapter);
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public IBinder onBind(Intent intent) {

        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onDestroy() {
        blueToothHelper1.removeAllReceiver(this);
        super.onDestroy();
    }

    @Override
    public void onScanStarted() {

    }

    @Override
    public void onDeviceFound(BluetoothDevice device) {

    }

    @Override
    public void onScanFinished() {

    }

    @Override
    public void onBondStateChanged(BluetoothDevice device, int oldState, int newState) {

    }

    @Override
    public void onConnectState(int state) {
        stopSelf();
    }

    @Override
    public void onBondState(int state) {

    }


}